﻿Module Module5
    Sub Main()
        Console.WriteLine("Module5 習題" & vbNewLine)

        ' 變數宣告
        Dim Name As String
        Dim Eng As Integer
        Dim Math As Integer
        Dim Sum As Integer
        Dim Avg As Double
        Dim s As String

        Do
            Console.Clear()

            ' 輸入學生姓名
            Console.Write("Name: ")
            Name = Console.ReadLine()

            ' 輸入並查驗英文成績
            Do
                Console.Write("Eng: ")
                s = Console.ReadLine()
                Eng = Val(s)
                If (Eng < 0) OrElse (Eng > 100) Then
                    Console.WriteLine("請輸入 0 ~ 100 之間的整數" & vbNewLine)
                End If
            Loop While (Eng < 0) OrElse (Eng > 100)

            ' 輸入並查驗數學成績
            Do
                Console.Write("Math: ")
                s = Console.ReadLine()
                Math = Val(s)
                If (Math < 0) OrElse (Math > 100) Then
                    Console.WriteLine("請輸入 0 ~ 100 之間的整數" & vbNewLine)
                End If
            Loop While (Math < 0) OrElse (Math > 100)

            ' 計算總分與平均
            Sum = Eng + Math
            Avg = Sum / 2

            ' 清除畫面並顯示結果
            Console.Clear()
            Console.WriteLine("Name: {0}", Name)
            Console.WriteLine("Eng : {0}", Eng)
            Console.WriteLine("Math: {0}", Math)
            Console.WriteLine("Sum : {0}", Sum)
            Console.WriteLine("Avg : {0:N1}", Avg)              ' 參考 2-27 頁
            Console.WriteLine("Avg : {0}", Avg.ToString("0.0")) ' 參考 2-29 頁
            If Avg >= 60 Then
                Console.WriteLine("及格")
            Else
                Console.WriteLine("不及格")
            End If

            Console.Write("評語: ")
            Select Case Avg
                Case 100
                    Console.WriteLine("完美")
                Case Is >= 90
                    Console.WriteLine("優秀")
                Case Is >= 80
                    Console.WriteLine("還不錯")
                Case Is >= 60
                    Console.WriteLine("再加油")
                Case Else
                    Console.WriteLine("沒念書喔")

            End Select
            Console.WriteLine(vbNewLine & "按任意鍵繼續 , 按 Esc 結束 .....")
        Loop Until Console.ReadKey().Key = ConsoleKey.Escape

    End Sub
End Module
